package com.nageoffer.shortlink.common.utils;
import java.util.Random;

public class RandomGenerator {

    // 定义允许的字符集（数字 + 大写字母）
    private static final String ALLOWED_CHARACTERS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    private static final Random random = new Random();

    /**
     * 生成一个随机的 6 位数字加字母组合的字符串
     *
     * @return 随机生成的 6 位字符串
     */
    public static String generateRandomCode(int length) {
        StringBuilder code = new StringBuilder(length);
        for (int i = 0; i < length; i++) {
            // 从 ALLOWED_CHARACTERS 中随机选择一个字符
            int randomIndex = random.nextInt(ALLOWED_CHARACTERS.length());
            char randomChar = ALLOWED_CHARACTERS.charAt(randomIndex);
            code.append(randomChar);
        }
        return code.toString();
    }
}